import { LoggerService } from "@nestjs/common";

export class HLogger implements LoggerService {
  log(logger: Logger, ...optionalParams: any[]) {
    console.log(`[${HLoggerLevel.log}] [${logger.datetime}] ${logger.oid} ${logger.method} ${logger.url} ${logger.status} ${logger.cost} params:${JSON.stringify(logger.params)} response:${JSON.stringify(logger.response)}`);
  }
  info(logger: Logger, ...optionalParams: any[]) {}
  error(logger: Logger, ...optionalParams: any[]) {
    console.log(`[${HLoggerLevel.error}] [${logger.datetime}] ${logger.oid} ${logger.method} ${logger.url} ${logger.status} ${logger.cost || 0} params:${JSON.stringify(logger.params)} response:${logger.stack}`);
  }
  warn(logger: Logger, ...optionalParams: any[]) {}
  debug?(logger: Logger, ...optionalParams: any[]) {}
  verbose?(logger: Logger, ...optionalParams: any[]) {}
}

export enum HLoggerLevel {
  log = 'LOG',
  info = 'INFO',
  warn = 'WARN',
  debug = 'DEBUG',
  error = 'ERROR'
}

export interface Logger {
  oid?: string;
  level?: HLoggerLevel;
  datetime?: string;
  status?: number;
  method?: string;
  url?: string;
  cost?: number;
  params?: object;
  response?: object;
  stack?: string;
}